package controller;

import dao.Album;
import model.AlbumModel;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class AlbumsServlet extends HttpServlet {
    private static final String ALBUMS_ATTRIBUTE = "albums";
    private static final String ALBUMS_VIEW = "view/albums.jsp";

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        AlbumModel albumModel = AlbumModel.getInstance();

        List<Album> albums = albumModel.getAlbums();
        request.setAttribute(ALBUMS_ATTRIBUTE, albums);

        RequestDispatcher view = request.getRequestDispatcher(ALBUMS_VIEW);
        view.forward(request, response);
    }
}
